import { _decorator, Node, Component, Prefab, instantiate, find, Label, tween, v3 } from 'cc';
import Utils from '../utils/Utils';


const { ccclass, property } = _decorator;

@ccclass
export default class MsgHints extends Component {
    setMsg(str: string) {
        this.node.getComponentInChildren(Label).string = str;
        this.node.setScale(v3(0, 0, 0))
        tween(this.node).to(0.1, { scale: v3(1.1, 1.1, 1) }).to(0.1, { scale: v3(0.9, 0.9, 1) }).to(0.1, { scale: v3(1, 1, 1) }).delay(0.5).by(0.5, { worldPosition: v3(0, 100, 0) }).removeSelf().start();
    }

    public static show(msg: string) {

        Utils.loadRes("common/MsgHints", "prefabs", Prefab, (err: Error, res: Prefab) => {
            let win: Node = instantiate(res)
            win.parent = find("Canvas");
            win.getComponent(MsgHints).setMsg(msg);
        });
    }

}